public class Text2 {
    // 递归、迭代模拟
    // 24.交换链表中的两两节点
    public ListNode swapPairs(ListNode head) {
        if(head == null || head.next == null){
            return head;
        }

        ListNode newhead = new ListNode(0);
        newhead.next = head;

        ListNode prev = newhead,cur = prev.next,next = cur.next,nnext = next.next;

        while(cur != null && next != null){
            prev.next = next;
            next.next = cur;
            cur.next = nnext;

            prev = cur;
            cur = nnext;
            if(cur != null){
                next = cur.next;
            }

            if(next != null){
                nnext = next.next;
            }
        }

        return newhead.next;

    }
}
